/**
 * Copyright (C) 2009 alex <me@alex.0x08.org>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package uber.netbsd.community.dao.comment;

import java.util.Calendar;
import java.util.List;
import javax.jdo.Query;
import uber.netbsd.community.dao.GenericManager;

/**
 * Persistence tier for Comment object
 * @author alex
 */
public class CommentManager extends GenericManager<Comment>{

    protected CommentManager() {

        super(Comment.class);
    }


    /** Gets the Comment with the specified ID, or null if no such Comment exists. */
    public Comment getComment(int id) {
        return get(id);
    }

    /** Returns a sorted list of all Comments in the system. */
    public List<Comment> getAllComments(String code) {

        if (getLogger().isDebugEnabled()) {
            getLogger().debug("__Comments, code="+ code);
        }
         Query q = persist.newQuery("SELECT FROM " + clazz.getName() + " WHERE code == :code");
       return (List) q.execute(code);

    }

    @Override
     public Comment saveOrUpdate(Comment obj) {
         obj.setCreated(Calendar.getInstance().getTime());
         return super.saveOrUpdate(obj);

     }


    /** Deletes an existing Comments.  May leave dangling references. */
    public void deleteComment(int CommentId) {
       delete(CommentId);
    }

    private static CommentManager instance;

    public static CommentManager getInstance() {

        if (instance==null)
            instance = new CommentManager();

        return instance;
    }
}
